import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css'

import Element from 'element-ui'
//
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'

// 数据字典
import dict from './components/Dict'

// 权限指令
import permission from './components/Permission'
import './assets/styles/element-variables.scss'
// global css
import './assets/styles/index.scss'

// 代码高亮
import VueHighlightJS from 'vue-highlightjs'
import 'highlight.js/styles/atom-one-dark.css'

import '@/assets/font_icon/iconfont.css'

import App from './App'
import store from './store'
import router from './router/routers'

import './assets/icons' // icon
import './router/index' // permission control

import { VueJsonp } from 'vue-jsonp'
// Vue.use(VueJsonp)

Vue.use(VueHighlightJS)
Vue.use(mavonEditor)
Vue.use(permission)
Vue.use(dict)
Vue.use(Element, {
  size: Cookies.get('size') || 'small' // set element-ui default size
})

Vue.use(VueJsonp)

Vue.config.productionTip = false

// 开发环境下修改sockjs的默认端口
if (process.env.NODE_ENV === 'development') {
  try {
    // 方法1: 尝试修改sockjs的默认端口
    const SockJS = require('sockjs-client');
    if (SockJS.prototype) {
      SockJS.prototype.DEFAULT_PORT = 10000;
    }

    // 方法2: 拦截WebSocket连接，替换端口
    const originalWebSocket = window.WebSocket;
    window.WebSocket = function(url, protocols) {
      if (url && url.indexOf('localhost:9999') !== -1) {
        url = url.replace('localhost:9999', 'localhost:10000');
        console.log('Redirected WebSocket connection from 9999 to 10000');
      }
      return new originalWebSocket(url, protocols);
    };

    // 方法3: 设置可能的开发工具端口
    window.__VUE_DEVTOOLS_HOST__ = 'localhost';
    window.__VUE_DEVTOOLS_PORT__ = 10000;
  } catch (e) {
    console.error('Failed to modify sockjs port:', e);
  }
}

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
